#include "pch.h"
#include "openglwrapper.h"
#include "GLImageBeautyComplexionFilter.h"

#include <glad/glad.h>
#include <GLFW/glfw3.h>
COpenglWrapper::COpenglWrapper()
	:whiten_factor_(0.6),
	smooth_factor_(0),
	ruddy_factor_(0)
	
{

}

COpenglWrapper::~COpenglWrapper()
{

}

bool COpenglWrapper::Initialize(int w, int h)
{
	glfwInit();
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	GLFWwindow* window = glfwCreateWindow(640, 480, "beautycore", NULL, NULL);
	if (window == NULL)
	{
		glfwTerminate();
		return false;
	}
	glfwMakeContextCurrent(window);
	glfwHideWindow(window);
	if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
	{
		
		return false;
	}
	image_beauty_filter_ = std::shared_ptr<GLImageBeautyComplexionFilter>(new GLImageBeautyComplexionFilter());
	image_beauty_filter_->Init(w, h);
	image_beauty_filter_->setComplexionLevel(0.0f, 0.0f, 0.8f);


	//create shader�� vao��texture and so on


	return true;
}

void COpenglWrapper::SetWhitenLevel(const float factor)
{
	whiten_factor_ = factor;
	image_beauty_filter_->setComplexionLevel(0, 0, factor);
}

void COpenglWrapper::SetSmoothLevel(const float factor)
{
	smooth_factor_ = factor;
}

cv::Mat COpenglWrapper::ProcessFrame(const cv::Mat& input_frame)
{
	return image_beauty_filter_->Draw(input_frame);
}